#ifndef FILESYSTEM_H_
#define FILESYSTEM_H_

#include "LowLevelDisk.h"
#include <vector>
#include <string>
#include <utility>
#include <iostream>
#include "LibEntry.h"
#include <algorithm>


using namespace std;

class FileSystem
{

private:

	LowLevelDisk* _LowLevelDisk;
	void myRead(int inode, char* buffer,int offset,int nBytes );

public:
	//This layer provides the following methods and uses the underlying low level local disk services:
	void IncHLinkNum(int inode);
	FileSystem(LowLevelDisk* ll);
	int createFile(char flag); // – creates a file returning its i-node number. Flag indicates whether the file to create is a regular file or a soft link.
	int getEntriesPerBlock();
	int createDir(); // – creates a directory, returning its i-node number.

	int getFileType(int inode);
	// – Returns the type of the file this i-node represents.

	void f_read(int inode, char* buffer,int offset,int nBytes );
	// – reads nBytes (at most) from the given file
	//(represented by this i-node) at the given offset inside the file into the buffer.

	void f_write(int inode,char* buffer,int offset,int nBytes );
	// – writes nBytes (at most) to the given file
	//(represented by this i-node) at the given offset inside that file, from the buffer.
	//If the amount to be written exceeds the current allocated block, a new block should be
	//allocated to accommodate the rest of the data.
	//Notice that both f_read and f_write only work on normal files (not directories).

	vector<LibEntry> d_read(int inode);
	// – reads the entire content of the directory file specified by the given i-node.
	//This information is then entered into a data structure (a vector or list) that lists the
	//files in this directory. Each element in this list therefore contains a filename and i-node number.

	void d_write(int inode, vector<LibEntry>  list );
	// – replaces the content of the given directory file (specified by i-node) with the
	//information stored in the list. The list has the same format as that returned by d_read().

	void f_delete(int inode); // – delete the file.

	void d_delete(int inode); // – delete the directory if it is empty.

};

#endif /* FILESYSTEM_H_ */
